package com.tequila.core.service.impl;

import com.google.common.collect.Lists;
import com.tequila.core.dao.CardCouponProductDao;
import com.tequila.core.service.CardCouponProductService;
import com.tequila.domain.dto.CardCouponProductDto;
import com.tequila.domain.entity.CardCouponProduct;
import com.tequila.domain.query.CardCouponProductQuery;
import fe.core.Assert;
import fe.core.BeanHelper;
import fe.core.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CardCouponProductServiceImpl implements CardCouponProductService {
    public static final Logger logger = LoggerFactory.getLogger(CardCouponProductServiceImpl.class);

    @Resource
    private CardCouponProductDao cardCouponProductDao;

    @Override
    public Pagination<CardCouponProductDto> queryPageListByParam(CardCouponProductQuery query) {
        Assert.assertNotNull(query);
        int total = cardCouponProductDao.queryPageCountByParam(query);

        List<CardCouponProductDto> list = Lists.newArrayList();
        if (total > 0) {
            list = cardCouponProductDao.queryPageListByParam(query);
        }
        return new Pagination<>(query, list, total);
    }

    @Override
    public CardCouponProductDto queryById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        CardCouponProduct cardCouponProduct = cardCouponProductDao.queryById(id);
        CardCouponProductDto cardCouponProductDto = new CardCouponProductDto();
        BeanHelper.copyProperties(cardCouponProductDto,cardCouponProduct);
        return cardCouponProductDto;
    }

    @Override
    public List<CardCouponProductDto> queryByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return cardCouponProductDao.queryByIdList(idList);
    }

    @Override
    public List<CardCouponProductDto> queryListByParam(CardCouponProductQuery query) {
        Assert.assertNotNull(query,"query不能为空!");
        return cardCouponProductDao.queryListByParam(query);
    }


    @Override
    public Long insert(CardCouponProduct entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        cardCouponProductDao.insert(entity);
        return entity.getId();
    }

    @Override
    public Long save(CardCouponProduct entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        cardCouponProductDao.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int updateById(CardCouponProduct param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return cardCouponProductDao.updateById(param);
    }

    @Override
    public int updateSelectiveById(CardCouponProduct param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return cardCouponProductDao.updateSelectiveById(param);
    }

    @Override
    public int deleteById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        return cardCouponProductDao.deleteById(id);
    }

    @Override
    public int deleteByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return cardCouponProductDao.deleteByIdList(idList);
    }
}
